package com.example.vertification.Utils;

import javax.servlet.http.HttpServletRequest;
import java.util.Random;

public class Utils {
    public static String generateCode() {
        StringBuilder sb = new StringBuilder(5);
        Random random = new Random();
        String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        for (int i = 0; i < 5; i++) {
            int index = (int) (random.nextFloat() * characters.length());
            sb.append(characters.charAt(index));
        }
        return sb.toString();
    }


    public static String getIpByServerlet(HttpServletRequest request){
        String ipAddress = request.getHeader("X-Forwarded-For");
        if (ipAddress == null) {
            ipAddress = request.getRemoteAddr();
        }
        return ipAddress;
    }


}
